import jsonpath

book_store = { "store": {
    "book": [
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      },
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}
# 第一本书的作者
print(book_store['store']['book'][0]['author'])
# 通过jsonpath提取  第一个参数提取数据对象，第二个参数jsonpath表达式 返回列表
print(jsonpath.jsonpath(book_store, '$.store.book[0].author'))
print(jsonpath.jsonpath(book_store,'$..author')[0])
# 提取第二本
print(jsonpath.jsonpath(book_store, '$.store.book[1].author')[0])
# 如果匹配的数据不存在  返回False
print(jsonpath.jsonpath(book_store,'$..autho'))